package com.cbt.cbtBlog.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;

public class SendEmailUtil {
   private String sendEmail = "1635531558@qq.com";
   private String password = "auattybextrtghjh";

   public boolean sendEmail(String receiveEmail, String code, String nickName) {
      JavaMailSenderImpl sender = new JavaMailSenderImpl();
      sender.setHost("smtp.qq.com");
      sender.setDefaultEncoding("utf-8");
      sender.setUsername(this.sendEmail);
      sender.setPassword(this.password);

      try {
         MimeMessage message = sender.createMimeMessage();
         MimeMessageHelper helper = new MimeMessageHelper(message);
         helper.setTo(receiveEmail);
         helper.setFrom(this.sendEmail);
         helper.setSubject("欢迎注册捷成论坛");
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss EEE");
         String str = "<!DOCTYPE html><html><head><meta charset='UTF-8'></head><body><p style='font-size: 20px;font-weight:bold;'>尊敬的：" + nickName + "，您好！</p><p style='text-indent:2em; font-size: 20px;'>欢迎注册捷成论坛，您本次的注册码是 <span style='font-size:30px;font-weight:bold;color:red'>" + code + "</span></p><p style='text-align:right; padding-right: 20px;'><a href='http://www.hyycinfo.com' style='font-size:18px'>衡阳市源辰信息科技有限公司技术部</a></p><span style='font-size:18px; float:right; margin-right: 20px;'>" + sdf.format(new Date()) + "</span></body><ml>";
         helper.setText(str, true);
         Properties prop = new Properties();
         prop.put("mail.smtp.auth", true);
         prop.put("mail.smtp.timeout", 20000);
         sender.setJavaMailProperties(prop);
         sender.send(message);
         return true;
      } catch (MessagingException var10) {
         var10.printStackTrace();
         return false;
      }
   }
}
